function [Mask,ScatterMask] = GetMask(ImageJRoiPath,SizeX,SizeY,ScatterRadius,MeanZ)
[Cx,Cy,Rx,Ry] = CaProcessing.ImageJRoiSetReadout(ImageJRoiPath);
Cx=reshape(Cx,1,1,[]);
Cy=reshape(Cy,1,1,[]);
Rx=reshape(Rx,1,1,[]);
Ry=reshape(Ry,1,1,[]);
Xs=(1:SizeX)';
Ys=1:SizeY;
Mask=(Xs-Cx).^2./Rx.^2+(Ys-Cy).^2./Ry.^2<=1;
NoPixels=SizeY*SizeX;
if exist('ScatterRadius','var')
	ScatterMask=(Xs-Cx).^2./(Rx+ScatterRadius).^2+(Ys-Cy).^2./(Ry+ScatterRadius).^2<=1&~Mask;
	if exist('MeanZ','var')
		for R=1:size(ScatterMask,3)
			ScatterMask(:,:,R)=MeanZ<median(MeanZ(ScatterMask(:,:,R)))&ScatterMask(:,:,R);
		end
	end
	ScatterMask=reshape(ScatterMask,NoPixels,[])';
	ScatterMask=ScatterMask./sum(ScatterMask,2);
end
Mask=reshape(Mask,NoPixels,[])';
Mask=Mask./sum(Mask,2);